import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_search_enter.dart';
import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/components/dialog/filter_dialog/custom_filter_right_sheet.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_title_chart_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/data/entities/double_control/get_user_by_id_entity.dart';
import 'package:enterprise_v6_app/app/modules/application/basic_information/personnel_management/people_information_list/people_information_list_controller.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';

/// 人员信息列表
class PeopleInformationListPage extends StatelessWidget {
  PeopleInformationListPage({super.key});

  final controller = Get.put(PeopleInformationListController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: controller,
      builder: (_) {
        return Scaffold(
          appBar: CustomAppBar(
            titleText: '人员信息',
          ),
          key: controller.popRightScaffoldKey,
          endDrawer: Container(
            width: AppDimens.sw - 70.w,
            height: AppDimens.sh,
            color: Colors.white,
            child: _getFilterWidget(),
          ),
          body: Container(
            color: const Color(0xffF5F5F6),
            padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.w),
            child: Column(
              children: [
                _getSearchConditionWidget(),
                AppGaps.vGap12,
                Expanded(
                    child: CustomEasyRefreshList<GetUserByIdEntity>(
                  key: controller.globalKey,
                  dataLoad: (pageIndex, pageSize, {String? search}) async {
                    return controller.getListData(pageIndex, pageSize);
                  },
                  itemBuilder: (GetUserByIdEntity item, int index) {
                    return CustomTitleChartPage(
                      title: item.nickname,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Row(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Expanded(
                                child: _getTextView(title: '性别：', value: item.sexName!, alignment: Alignment.centerLeft),
                              ),
                              Expanded(
                                child: _getTextView(title: '学历：', value: item.educationName!, alignment: Alignment.centerLeft),
                              ),
                              Expanded(
                                child: _getTextView(title: '部门：', value: item.departmentName!, alignment: Alignment.centerLeft),
                              )
                            ],
                          ),
                          AppGaps.vGap12,
                          _getTextView(title: '工号：', value: item.jobNumber!),
                          AppGaps.vGap12,
                          _getTextView(title: '岗位名称：', value: item.positionName!),
                          AppGaps.vGap12,
                          _getTextView(title: '职称：', value: item.titleName!),
                          AppGaps.vGap12,
                          _getTextView(title: '证书临期提醒/天：', value: item.certificateRemind.toString()),
                          AppGaps.vGap12,
                          _getTextView(title: '是否取得注册安全师资格证：', value: item.safetyEngineer! == 1 ? '是' : '否'),
                          AppGaps.vGap12,
                          _getTextView(title: '是否具备化工学历背景：', value: item.chemistry! == 1 ? '是' : '否'),
                          AppGaps.vGap12,
                          _getTextView(title: '毕业院校：', value: item.school!),
                        ],
                      ),
                    ).clickOnce(() {
                      Get.toNamed(AppRoutes.peopleInformationDetails, arguments: item.id);
                    });
                  },
                ))
              ],
            ),
          ),
        );
      },
    );
  }

  ///获取条件搜索项
  Widget _getSearchConditionWidget() {
    return Row(
      children: [
        Expanded(
            child: CustomSearchEnter(
          height: 32.w,
          hintText: '请输入姓名/职称/工号名称',
          text: controller.search,
          onCallBack: (value) {
            controller.search = value;
            controller.refreshPage();
          },
        )),
        AppGaps.hGap8,
        _screen(),
      ],
    );
  }

  ///获取右侧筛选样式
  Widget _getFilterWidget() {
    return CustomFilterRightSheet(
      dataList: controller.filterList,
      onConfirm: controller.screenConfirm,
      isRadio: true,
    );
  }

  ///筛选
  Widget _screen() {
    return Container(
      width: 36.w,
      height: 32.w,
      alignment: Alignment.center,
      decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8.w)),
      child: SvgPicture.asset(
        AppImages.icon_search_screen,
        width: 18.w,
        height: 16.w,
      ),
    ).clickOnce(controller.screen);
  }

  /// 获取字段显示
  Widget _getTextView({required String title, required String value, AlignmentGeometry? alignment}) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          title,
          style: TextStyle(
            fontSize: 13.sp,
            height: 1.2,
            fontWeight: FontWeight.w400,
            color: const Color(0xffA5A6B5),
          ),
        ),
        Expanded(
            child: Container(
          alignment: alignment ?? Alignment.centerRight,
          child: Text(
            value,
            style: TextStyle(
              fontSize: 12.sp,
              height: 1.2,
              fontWeight: FontWeight.w400,
              color: const Color(0xff495061),
            ),
          ),
        ))
      ],
    );
  }
}
